package com.second.app.exception;

import com.second.app.common.SecondResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author gyz
 * @date 2020/12/26 15:46
 */
@Slf4j
@ControllerAdvice
public class ExceptionHandle {


    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public SecondResponse handle(Exception e) {
        if (e instanceof MyException) {
            MyException exception = (MyException) e;
            return SecondResponse.error(exception.getCode(), exception.getMessage());
        }
        return null;
    }

}
